﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Permission.Interface;
using Microhard.Core;
using Microhard.Permission.MVCFilter;
using Microhard.Permission.Models;
using Microhard.WarehouseInsp.Buz.Models;
using System.Text;

namespace Microhard.WarehouseInsp.WebUI.Models
{
    public static class UrlActionExtension
    {
        public static System.Web.Mvc.MvcHtmlString AuthLink(this System.Web.Mvc.UrlHelper helper, string actionName, string controllerName, string areaName)
        {
            IFuncAuthorization ifc = IoC.Resolve<IFuncAuthorization>();
            var user = MVCFilterAtrForLogon.GetLogonUser();

            PermissionRequest pr = new PermissionRequest();
            pr.RequestOperation = new Operation();
            pr.RequestResouce = new Resouce();
            pr.RequestOperation.KeyName = actionName;
            pr.RequestResouce.KeyName = controllerName;
            pr.UserName = user.UserName;
            List<string> hasPms = new List<string>();
            List<Microhard.Permission.Models.Permission> currentPermissions = null;

            if (ifc.IsApprove(pr, out hasPms, out currentPermissions))
            {
                string url = helper.Action(actionName, controllerName, new { area = areaName });
                return new MvcHtmlString(url);
            }
            return new MvcHtmlString("#");
        }
    }
}